package com.whq.thrift.api.as.demo01.asAccount;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.whq.common.StringUtil;
import com.whq.thrift.api.common.constants.CommonErrorCodeConstants;
import com.whq.thrift.api.common.thriftserver.ResponseBase;
import com.whq.thrift.api.common.thriftserver.ResponseDataListBase;
import com.whq.thrift.api.thrift.as.service.service.AsBaseSpringService;

public class Test {
	public ResponseBase list(AsBaseSpringService asBaseSpringService, String method, Map<String, String> params, Map<String, String> ctx) {
		
		List list = asBaseSpringService.getSqlSession().selectList("User.selectRecords");
		
		ResponseDataListBase response = new ResponseDataListBase();
		response.setReturnCode(CommonErrorCodeConstants.ERR_CODE_SUCCESS);
		response.setReturnMsg("success");
		response.setData(list);
		
		return response;
	}
	
	public ResponseBase add(AsBaseSpringService asBaseSpringService, String method, Map<String, String> params, Map<String, String> ctx) {
		String name = params.get("name");
		if (StringUtil.isBlank(name)) {
			return new ResponseBase(CommonErrorCodeConstants.ERR_CODE_LACK_PARAM, "缺少参数：name");
		}
		
		Map<String, String> parameter = new HashMap<String, String>(0);
		parameter.put("name", name);
		asBaseSpringService.getSqlSession().insert("User.inserRecord", parameter);
		
		return new ResponseBase(CommonErrorCodeConstants.ERR_CODE_SUCCESS);
	}

}
